import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  
  return {
    plugins: [vue()],
    // 设置基础路径为 /m
   // base: '/m/',
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    server: {
      port: parseInt(env.VITE_DEV_SERVER_PORT || '3003'),
      host: env.VITE_DEV_SERVER_HOST || '0.0.0.0',
      strictPort: true,
      hmr: {
        host: env.VITE_HMR_HOST || 'localhost'
      },
      // 允许所有来源
      cors: true,
      // 允许外部访问
      allowedHosts: true
    },
    build: {
      outDir: 'dist',
      sourcemap: true
    },
    // 优化移动端性能
    optimizeDeps: {
      include: ['vue', 'vue-router', 'pinia']
    }
  }
})